Python: Make workspace file hooks opt-in for GitHubCopilotAgent - #7517
Python: Make workspace file hooks opt-in for GitHubCopilotAgent#7517giles17 wants to merge 1 commit into
Conversation
Session behavior currently varies with the working directory the agent runs in, because the CLI picks up file hook definitions from the checkout. Give `enable_file_hooks` an explicit default of False in `_build_session_kwargs` so a session behaves consistently regardless of the checkout, and let callers opt in through `default_options` or per-run options. Add the option to `GitHubCopilotOptions` with documentation, and cover the default, the opt-in, and the per-run override with tests. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 42d0b850-56e0-4346-9b3e-cc3de339b16b
Python Test Coverage Report •
Python Unit Test Overview
|
||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Pull request overview
This PR makes GitHubCopilotAgent session behavior deterministic across working directories by explicitly defaulting workspace-driven Copilot SDK session options (starting with enable_file_hooks) to opt-in, preventing implicit .github/hooks/ influence unless callers request it.
Changes:
- Add a module-level
_WORKSPACE_CONFIG_DEFAULTSmap and apply its defaults in_build_session_kwargswhen the resolved option value isNone. - Document
enable_file_hooksas a supportedGitHubCopilotOptionskey and explain the opt-in behavior and security considerations. - Update and add unit tests to validate the new default and precedence rules (runtime options override agent defaults).
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| python/packages/github_copilot/agent_framework_github_copilot/_agent.py | Introduces _WORKSPACE_CONFIG_DEFAULTS, documents enable_file_hooks, and applies an explicit default in session kwargs construction. |
| python/packages/github_copilot/tests/test_github_copilot_agent.py | Updates strict resume-session assertion and adds tests covering default/off + override precedence for enable_file_hooks. |
| python/packages/github_copilot/README.md | Documents workspace-driven options and how to opt into enable_file_hooks. |
| python/packages/github_copilot/AGENTS.md | Records the convention for session option defaults and where to add future workspace-driven defaults. |
| # the CLI does on the host. The agent leaves them off so a session behaves the same way in | ||
| # every checkout; callers that want the checkout-driven behavior can turn each one back on | ||
| # through ``default_options`` or per-run options. | ||
| _WORKSPACE_CONFIG_DEFAULTS: dict[str, bool] = { |
There was a problem hiding this comment.
Could we preserve the existing default or treat this as an explicit breaking migration? With the pinned SDK/CLI, omitting enable_file_hooks loads repository hooks, while this explicit False disables them. Existing consumers of this stable package will silently stop running .github/hooks/ after upgrading unless they discover and add the new opt-in.
| # the CLI does on the host. The agent leaves them off so a session behaves the same way in | ||
| # every checkout; callers that want the checkout-driven behavior can turn each one back on | ||
| # through ``default_options`` or per-run options. | ||
| _WORKSPACE_CONFIG_DEFAULTS: dict[str, bool] = { |
There was a problem hiding this comment.
Would it make sense to keep the enable_file_hooks=False default inside _build_session_kwargs until we have a second workspace-controlled option? At the moment, _WORKSPACE_CONFIG_DEFAULTS only contains a single value and has a single caller. Removing it simplifies the code to a single conditional.
Motivation & Context
GitHubCopilotAgentsession behavior depends on which working directory the agent runs in. The Copilot CLI loads file hooks from a checkout's.github/hooks/, controlled by the SDKenable_file_hookssession option, and the agent never sets it, so it inherits the runtime default.That makes runs harder to reason about and reproduce: the same agent, the same options, and the same prompt can behave differently based only on the directory the process started in. It is also invisible to callers, since it sits outside the small set of options the agent gives an explicit default.
Description & Review Guide
What are the major changes?
_build_session_kwargsnow applies an explicit default forenable_file_hooks(False), alongside the existingon_permission_requestdefault. The defaults live in a module-level_WORKSPACE_CONFIG_DEFAULTSmap so future additions have one home.None, so an explicitTrueorFalsefrom eitherdefault_optionsor per-run options is preserved.enable_file_hooksis now a documentedGitHubCopilotOptionskey.AGENTS.mdrecords the convention.What is the impact of these changes?
.github/hooks/definitions being picked up automatically needenable_file_hooks=Trueindefault_optionsor per-run options. Nothing else on the wire changes, and theon_permission_request/on_pre_tool_usepaths are untouched.enable_host_git_operations, are deliberately left alone so prompt quality is unaffected.assert_called_once_withonresume_sessionand needed the new kwarg added; that is a strict-matcher update, not a behavior change.What do you want reviewers to focus on?
Falseis the right default forenable_file_hooks, and whether the opt-in path reads clearly in the README.Related Issue
Fixes #7516
Contribution Checklist
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.